<template>
  <div class="scrolling-list-container">
    <div class="list-wrapper" style="padding: 10px">
      <div id="echart-box-chart" style="width: 100%; height: 100%"></div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
import * as echarts from "echarts";

export default {
  name: "SimCard",
  components: {
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    request({
      url: "/zk/substation/count-by-area",
      method: "get",
    }).then((res) => {
      console.log("result", res);
      this.initChart(res.data);
    });
  },
  methods: {
    initChart(param) {
      this.chart = echarts.init(document.getElementById("echart-box-chart"));
      const option = {
        title: {
          text: "",
          textStyle: {
            color: "#FFFFFF", // Set title text color to white
            fontSize: 14,
          },
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: ["变电站区域分布统计"],
          textStyle: {
            color: "#FFFFFF", // Set legend text color to white
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          top: "10%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          boundaryGap: true,
           scale: true,
          data: param.dates,
          axisLabel: {
            textStyle: {
              color: "#FFFFFF", // Set x-axis label text color to white
            },
          },
          axisLine: {
            lineStyle: {
              color: "#FFFFFF", // Set x-axis line color to white
            },
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255,255,255,0.2)", // Set x-axis grid line color
            },
          },
        },
        yAxis: {
          type: "value",
          axisLabel: {
            textStyle: {
              color: "#FFFFFF", // Set y-axis label text color to white
            },
          },
          axisLine: {
            lineStyle: {
              color: "#FFFFFF", // Set y-axis line color to white
            },
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255,255,255,0.2)", // Set y-axis grid line color
            },
          },
        },
        series: [
          {
            name: "区域分布统计",
            type: "bar",
            data: param.values,
            barWidth: '60%', // Set the bar width to make columns thinner
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#6BD0FF" },
                { offset: 1, color: "#2F7CFF" },
              ]),
            },
            label: {
              show: true,
              color: "#FFFFFF", // Set label text color to white
              position: "top",
            },
          },
        ],
      };
      this.chart.setOption(option);
      window.addEventListener("resize", this.handleResize);
    },
    handleResize() {
      if (this.chart) {
        this.chart.resize();
      }
    },
  },
  beforeDestroy() {
    if (this.chart) {
      window.removeEventListener("resize", this.handleResize);
      this.chart.dispose();
    }
  },
};
</script>

<style lang="scss" scoped>
.list-wrapper {
  height: 243px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;

  ul {
    list-style: none;
    padding: 0;
    li,
    a {
      display: block;
      display: flex;
      justify-content: space-between;
      font-size: 15px;
    }
  }
}
/* You can write your component-specific styles here */
</style>
